Skip to content

Conversation

@hsjobeki
Copy link
Contributor

Motivation

Reading through the docs of sort. I found them a bit hard to understand.
I think the code examples could benefit from some prose that explains them upfront.
It is non-obvious how to interpret the code. especially -> does this mean nix's implication operator?

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

1. Transitivity
If a is less than b; b is less than c. Then it follows that a is less than c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a is less than b; b is less than c. Then it follows that a is less than c
If a is less than b and b is less than c, then it follows that a is less than c.

Comment on lines +4031 to +4032
If a is NOT less than b; b is NOT less then a; a and b are equal according to the comparator.
If b is equal to c then it follows that a is equal to c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a is NOT less than b; b is NOT less then a; a and b are equal according to the comparator.
If b is equal to c then it follows that a is equal to c
First, let us define *equivalence* with respect to some comparator:
If x is *not* less than y and x is *not* less then y, then x and x are equivalent according to the comparator.
Having done that, now we can define the transitivity of this equivalence:
If a is equivalent to b and b is equivalent to c, then it follows that a is equivalent to c,

I think using different variables here make the prose much less confusing. Your version IMO made the mistake of extending the a: b: ... scope too far: the second a and b are not the same.

Copy link
Contributor Author

@hsjobeki hsjobeki Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, i can make the sentence more correct in that regard. But my other point was to avoid the term transitivity in its own definition. Because at that point i (or the reader) doesn't understand what it means.

I also wonder if we need to define the eq function, when the point is to explain the concept, we shouldn't over formalize, but make sure the required property is understood by keeping the explanation simple.

If b is equal to c then it follows that a is equal to c
```nix
let equiv = a: b: (!comparator a b && !comparator b a); in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let equiv = a: b: (!comparator a b && !comparator b a); in
let equiv = x: y: (!comparator x y && !comparator x y); in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants